/*
*    Clean AJAX Engine v4.0
*    Copyright (C) 2005-2006 Carlos Eduardo Goncalves (cadu.goncalves@gmail.com)
*
*    This program is free software; you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation; either version 2 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License
*    along with this program; if not, write to the Free Software
*    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

/**
* Provides a generic XSLT processor.
* @author Carlos Eduardo Goncalves
*/

/**
* <p>XSLT processor tool constructor.</p>
*/
function XsltTool(){
}

/** 
* <p>Transforms a XML document based on a XSLT document.</p>
* @param origin
*		XML document to be transformed.
* @param style
*		XSLT document used to perform the transformation.
* @return
*		<code>String</code> that represents the result of the transformation.
*/
XsltTool.transform = function(origin, style){
  try{
    if(typeof XSLTProcessor != "undefined"){			
	  var proc = new XSLTProcessor();
	  proc.importStylesheet(style);
	  return (new XMLSerializer()).serializeToString(proc.transformToDocument(origin));
    }
	else 
	if(window.ActiveXObject) {	
	  var proc = Engine.buildActiveX(Engine.ACTIVEX_DOM);
	  proc.async = "false";	  
	  proc.load(origin);	
	  return proc.transformNode(style);	
    }
	else
     return xsltProcess(origin, style);	
 } catch(e){Engine.reportException(null, e);}	
}